﻿using org.xisoft.game.utils.game;
using System.Diagnostics;
using System.IO;

namespace org.xisoft.game.GobangModule.Chess
{
    class GobangBroad: ChessBoardBase
    {
        public const byte MAXX = 15;
        public const byte MAXY = 15;

        private byte itemCount;

        public GobangBroad()
            :base(MAXX, MAXY)
        {

        }
        public override void DoNextMove(MoveAction moveAction)
        {
            itemCount++;
            moveAction.CurrentChessman = new ChessItem { Index = itemCount, IsBlack = IsCurrentBlackMove };
            base.DoNextMove(moveAction);
        }


        [DebuggerNonUserCode]
        [DebuggerStepThrough]
        protected override void Undo(MoveAction moveAction)
        {
            this[moveAction.ToX, moveAction.ToY] = null;
            itemCount--;
        }


        private void CreateChessItem(int x,int y,bool isBlack,byte index)
        {
            this[x, y]= new ChessItem { PositionX = x, PositionY = y, IsBlack = isBlack, Index = index };
        }

        public override void Reset()
        {
            base.Reset();
            int halfX = MaxX / 2;
            int halfY = MaxY / 2;
            itemCount = 1;
            CreateChessItem(halfX, halfY, IsCurrentBlackMove, itemCount++);
            CreateChessItem(halfX, halfY + 1, !IsCurrentBlackMove, itemCount++);
            CreateChessItem(halfX + 1, halfY + 1, IsCurrentBlackMove, itemCount++);
            CreateChessItem(halfX + 1, halfY, !IsCurrentBlackMove, itemCount++);

        }
    }
}
